package com.example.aaa_viewpager;

import java.util.List;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

public class MyPagerAdapter extends PagerAdapter{
	
	private List<View>viewList;
	private List<String>titleList;
	
	 public MyPagerAdapter(List<View>viewList,List<String>titleList)
	 {
		 
		 this.viewList = viewList;
		 this.titleList = titleList;
	 }

	
	/*
	 * 返回的是頁卡的數量
	 * */
	
	@Override
	public int getCount() 
	{
		// TODO Auto-generated method stub
		return viewList.size();
	}
	
	
	/*
	 * View是否來自於對象
	 * */

	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		// TODO Auto-generated method stub
		return arg0==arg1;
	}
	
	/*
	 * 實作一個頁卡
	 * */
	
	@Override
	public Object instantiateItem(ViewGroup container, int position) {
		// TODO Auto-generated method stub
		container.addView(viewList.get(position));
		return viewList.get(position);
		
	}
	
	/*
	 * 銷毀一個頁卡
	 * */
	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		// TODO Auto-generated method stub
		container.removeView(viewList.get(position));
	}
	
	/*
	 * 設置viewpager頁卡的標題
	 * */
	@Override
	public CharSequence getPageTitle(int position)
	{
		// TODO Auto-generated method stub
		return titleList.get(position);
	}

}
